import sys
print("当前Python路径:", sys.executable)
print("模块搜索路径:", sys.path)
from mcp.server.fastmcp import FastMCP

# 创建MCP服务器
mcp = FastMCP("Numerical Operations Server")

@mcp.tool()
def add(a: float, b: float) -> str:
    """执行加法运算"""
    return f"结果: {a + b}"

@mcp.tool()
def subtract(a: float, b: float) -> str:
    """执行减法运算"""
    return f"结果: {a - b}"

@mcp.tool()
def multiply(a: float, b: float) -> str:
    """执行乘法运算"""
    return f"结果: {a * b}"

@mcp.tool()
def divide(a: float, b: float) -> str:
    """执行除法运算，包含除零错误处理"""
    try:
        if b == 0:
            return "错误: 除数不能为零"
        result = a / b
        return f"结果: {result}"
    except Exception as e:
        return f"计算错误: {str(e)}"

import math

@mcp.tool()
def sqrt(a: float) -> str:
    """执行开方运算，处理负数输入错误"""
    if a < 0:
        return "错误: 不能对负数进行开方运算"
    result = math.sqrt(a)
    return f"结果: {result}"

if __name__ == "__main__":
    mcp.run(transport="stdio")